<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/7/28/028
 * Time: 23:25
 */

namespace app\api\controller;

use think\Db;

class News extends Rest{

    public function index(){

    }

    public function getNews(){
        if (1 != self::check_power(1)) {
            return $this->data;
        }
        $data = Db::name('news')->where(['data_state' => 1])->order('datatime desc')->page($this->page_num, $this->page_limit)->select();
        foreach ($data as $key => $value) {
            if ($value['thumimg']) {
                $imgs = explode(',', $value['thumimg']);
                $data[$key]['thumimg'] = $imgs;
            } else {
                $data[$key]['thumimg'] = [];
            }
            if($value['datatime']){
                $strtimes = explode(" ",$value['datatime']);
                $timearray = explode("-",$strtimes[0]);
                $year = $timearray[0];
                $month = $timearray[1];
                $day = $timearray[2];
                $data[$key]['year'] = $year;
                $data[$key]['month'] = $month;
                $data[$key]['day'] = $day;
            }
        }
        $this->data['msg']  = '获取成功';
        $this->data['data'] = $data;
        return $this->data;
    }

    public function editNews(){

    }

    public function addNews(){

    }

    public function delNews(){

    }

}